package edu.sctu.zhangwang.month201506.day20150617;

import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

/**
 * Created by user10 on 2015/6/17.
 */
public class HttpPost {
    public static void post(String path,String param){
        PrintWriter out = null;
        BufferedReader in = null;
        int result = 0;
        byte[] bytes = new byte[1024];
        try {
            URL url = new URL(path);
            try {
                URLConnection connection = url.openConnection();
                connection.setDoInput(true);
                connection.setDoOutput(true);

                out = new PrintWriter(connection.getOutputStream());
                out.print(param);
                out.flush();

//                in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
                InputStream inputStream = connection.getInputStream();

                int red;
                while ((red=inputStream.read(bytes))!= -1){
                    result +=red;
                    System.out.println(red);
                }
                System.out.println("最后*************\n\n"+result);
                in.close();
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        post("http://w.qq.com/","text=872455356&password=zw520.");
    }

}
